package com.kfm.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;

public class HashMapDemo {

    public static void main(String[] args) {
        // HashMap<String, String> hashMap = new HashMap<>();
        // hashMap.put("username", "pomelo");
        // hashMap.put("password", "123456");
        // hashMap.put("password", "wxlp0323");
        // // 相同的key只会保留一个
        // hashMap.forEach((k, v) -> System.out.println(k + "=" + v));
        // Collection<String> values = hashMap.values();
        // System.out.println(values);

        HashMap<Game, String> map = new HashMap<>();
        Game g1 = new Game("王者荣耀", 2.3);
        Game g2 = new Game("原神", 5.0);
        Game g3 = new Game("元梦之星", 3.4);
        Game g4 = new Game("蛋仔派对", 4.3);
        Game g5 = new Game("王者荣耀", 2.3);
        map.put(g1, "腾讯");
        map.put(g2, "米哈游");
        map.put(g3, "腾讯");
        map.put(g4, "网易");
        map.put(g5, "腾讯");
        // key的重复通过 HashCode以及Equals校验
        // map.forEach((k, v) -> System.out.println(k + "=" + v));

        TreeMap<Game, String> treeMap = new TreeMap<>();
        treeMap.put(g1, "腾讯");
        treeMap.put(g2, "米哈游");
        treeMap.put(g3, "腾讯");
        treeMap.put(g4, "网易");
        treeMap.put(g5, "腾讯");
        treeMap.forEach((k, v) -> System.out.println(k + "=" + v));

    }
}
